package com.antonytrupe.fatcontroller.pc.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.antonytrupe.fatcontroller.EngineListView;
import com.antonytrupe.fatcontroller.Engine;

public class EnginePanel extends JPanel implements ActionListener,
		com.antonytrupe.fatcontroller.ui.EngineView {
	private static final String TAKE_CONTROL = "take_control";
	private static final long serialVersionUID = -5746434108038346323L;
	private JButton takeControlButton;
	private Engine engine;
	private EngineListView controller;

	public EnginePanel(Engine engine, EngineListView controller) {
		this.engine = engine;
		this.controller = controller;
		this.add(new JLabel(engine.name));
		takeControlButton = new JButton("Take Control");
		takeControlButton.setActionCommand(TAKE_CONTROL);
		takeControlButton.addActionListener(this);
		this.add(takeControlButton);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (TAKE_CONTROL.equals(e.getActionCommand())) {
			try {
				controller.showEngineControlPanel(this.engine);

			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}

	}

}
